const companyModel = require("../model/companyModel")

module.exports = {
    addList(data) {
        // console.log(data)
        // return companyModel.create(data)
        // 过滤重复元素
        return Promise.all(data.map(obj => {
            return companyModel.findOneAndUpdate({
                title: obj.title 
            }, {
                $set: obj
            }, {
                upsert: true
            }).exec()
        }))
    },
    getList() {
        return companyModel.find()
    },
    update(id, data) {
        return companyModel.findByIdAndUpdate(id, data)
    },
    delete(data) {
        console.log(data.id)
        return companyModel.findOneAndDelete({ _id: data.id })
    }
}